home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / 1.2 / scripts / ripply-anim.scm.z / ripply-anim.scm
Text File  |  2002-07-08  |  4KB  |  106 lines

  1. ; "Rippling Image" animation generator (ripply-anim.scm)
  2. ; Adam D. Moss (adam@foxbox.org)
  3. ; 97/05/18
  4. ;
  5. ; Designed to be used in conjunction with a plugin capable
  6. ; of saving animations (i.e. the GIF plugin).
  7. ;
  8.  
  9. (define (copy-layer-ripple dest-image dest-drawable source-image source-drawable)
  10.   (gimp-selection-all dest-image)
  11.   (gimp-edit-clear dest-drawable)
  12.   (gimp-selection-none dest-image)
  13.   (gimp-selection-all source-image)
  14.   (gimp-edit-copy source-drawable)
  15.   (gimp-selection-none source-image)
  16.       (let ((floating-sel (car (gimp-edit-paste dest-drawable FALSE))))
  17.     (gimp-floating-sel-anchor floating-sel)))
  18.  
  19. (define (script-fu-ripply-anim img drawable displacement num-frames)
  20.   (let* ((old-bg (car (gimp-palette-get-background)))
  21.      (width (car (gimp-drawable-width drawable)))
  22.      (height (car (gimp-drawable-height drawable)))
  23.      (ripple-image (car (gimp-image-new width height GRAY)))
  24.      (ripple-layer (car (gimp-layer-new ripple-image width height GRAY_IMAGE "Ripple Texture" 100 NORMAL))))
  25.  
  26.  ; this script generates its own displacement map
  27.  
  28.     (gimp-image-undo-disable ripple-image)
  29.     (gimp-palette-set-background '(127 127 127) )
  30.     (gimp-image-add-layer ripple-image ripple-layer 0)
  31.     (gimp-edit-fill ripple-layer BG-IMAGE-FILL)
  32.     (plug-in-noisify 1 ripple-image ripple-layer FALSE 1.0 1.0 1.0 0.0)
  33.     ; tile noise
  34.     (set! rippletiled-ret (plug-in-tile 1 ripple-image ripple-layer (* width 3) (* height 3) TRUE))
  35.     (gimp-image-undo-enable ripple-image)
  36.     (gimp-image-delete ripple-image)
  37.  
  38.     (set! rippletiled-image (car rippletiled-ret))
  39.     (set! rippletiled-layer (cadr rippletiled-ret))
  40.     (gimp-image-undo-disable rippletiled-image)
  41.  
  42.     ; process tiled noise into usable displacement map
  43.     (plug-in-gauss-iir 1 rippletiled-image rippletiled-layer 35 TRUE TRUE)
  44.     (gimp-equalize rippletiled-layer TRUE)
  45.     (plug-in-gauss-rle 1 rippletiled-image rippletiled-layer 5 TRUE TRUE)
  46.     (gimp-equalize rippletiled-layer TRUE)
  47.  
  48.     ; displacement map is now in rippletiled-layer of rippletiled-image
  49.  
  50.     ; loop through the desired frames
  51.  
  52.     (set! remaining-frames num-frames)
  53.     (set! xpos (/ width 2))
  54.     (set! ypos (/ height 2))
  55.     (set! xoffset (/ width num-frames))
  56.     (set! yoffset (/ height num-frames))
  57.  
  58.     (let* ((out-imagestack (car (gimp-image-new width height RGB))))
  59.  
  60.       (gimp-image-undo-disable out-imagestack)
  61.       
  62.       (while (> remaining-frames 0)
  63.          (set! dup-image (car (gimp-channel-ops-duplicate rippletiled-image)))
  64.          (gimp-image-undo-disable dup-image)
  65.          (gimp-crop dup-image width height xpos ypos)
  66.          
  67.          (set! layer-name (string-append "Frame "
  68.             (number->string (- num-frames remaining-frames) 10)
  69.             " (replace)"))
  70.          (set! this-layer (car (gimp-layer-new out-imagestack
  71.                            width height RGB
  72.                            layer-name 100 NORMAL)))
  73.          (gimp-image-add-layer out-imagestack this-layer 0)
  74.          
  75.          (copy-layer-ripple out-imagestack this-layer img drawable)
  76.          
  77.          (set! dup-layer (car (gimp-image-get-active-layer dup-image)))
  78.          (plug-in-displace 1 out-imagestack this-layer
  79.                    displacement displacement
  80.                    TRUE TRUE dup-layer dup-layer 2)
  81.          
  82.          (gimp-image-undo-enable dup-image)
  83.          (gimp-image-delete dup-image)
  84.          
  85.          (set! remaining-frames (- remaining-frames 1))
  86.          (set! xpos (+ xoffset xpos))
  87.          (set! ypos (+ yoffset ypos)))
  88.       
  89.       (gimp-image-undo-enable rippletiled-image)
  90.       (gimp-image-delete rippletiled-image)
  91.       (gimp-palette-set-background old-bg)
  92.       (gimp-image-undo-enable out-imagestack)
  93.       (gimp-display-new out-imagestack))))
  94.  
  95. (script-fu-register "script-fu-ripply-anim"
  96.             _"<Image>/Script-Fu/Animators/Rippling..."
  97.             "Ripple any image by creating animation frames as layers"
  98.             "Adam D. Moss (adam@foxbox.org)"
  99.             "Adam D. Moss"
  100.             "1997"
  101.             "RGB* GRAY*"
  102.             SF-IMAGE "Image to Animage" 0
  103.             SF-DRAWABLE "Drawable to Animate" 0
  104.             SF-ADJUSTMENT _"Rippling Strength" '(3 0 256 1 10 1 0)
  105.             SF-ADJUSTMENT _"Number of Frames" '(15 0 256 1 10 0 1))
  106.